1 00:00:00,540 --> 00:00:10,080 Hello and welcome to this lecture in this part two of the barns and the ball lectures we will be implementing. 2 00:00:10,080 --> 00:00:20,820 Coalition detection the coalition detection will check if the ball is touchin or colliding with the 3 00:00:20,820 --> 00:00:22,620 wars on the campus. 4 00:00:22,710 --> 00:00:24,650 There are four walls of the campus. 5 00:00:24,660 --> 00:00:29,120 You've got the top the bottom left and the right. 6 00:00:29,190 --> 00:00:37,050 So we'll implement coalition detection to spot or detect if there's any coalition between any of the 7 00:00:37,050 --> 00:00:37,800 walls. 8 00:00:37,890 --> 00:00:48,960 If there is any will will create calculations so that the ball will change the direction of this movement. 9 00:00:49,200 --> 00:00:55,530 We are going to create a variable called ball radius. 10 00:00:55,530 --> 00:01:03,900 This variable will hold the radius of the drawn circle that will be used to perform the cuk relations. 11 00:01:04,200 --> 00:01:13,790 OK so let's create the variable create its other top here called fireable. 12 00:01:14,490 --> 00:01:17,760 We are very low call ball 13 00:01:20,590 --> 00:01:22,150 radius. 14 00:01:22,430 --> 00:01:24,120 Now give it a value 15 00:01:26,730 --> 00:01:29,000 of 10. 16 00:01:32,460 --> 00:01:39,870 Now that we've created a variable called ball radius is less of date are drawn ball function. 17 00:01:39,960 --> 00:01:47,690 So where we've got the rate is here we removed this value and replace that will borate Yes 18 00:01:52,800 --> 00:01:56,330 we can send them. 19 00:02:01,290 --> 00:02:01,800 All right. 20 00:02:01,800 --> 00:02:08,730 This is a value we need to remove the actual radius and then to get too many commas there. 21 00:02:08,800 --> 00:02:13,880 So that's the X Y variable and this is the borate of variable. 22 00:02:14,220 --> 00:02:19,770 And then there's this the Ark where the ark starts and this is where they are. 23 00:02:19,940 --> 00:02:32,520 NS There are four walls for the ball to bounce off the Cambers with the top the bottom the left and 24 00:02:32,520 --> 00:02:33,630 the right. 25 00:02:35,290 --> 00:02:43,780 Okay let's determine the how we cut callate the coalition point of the Bosso conference. 26 00:02:43,930 --> 00:02:54,520 We got to do this using if statements okay we're going to place the statement just below the drop ball 27 00:02:55,090 --> 00:02:56,220 function. 28 00:02:56,710 --> 00:03:04,930 So what we are going to say is we're going to start with the left and the right wars. 29 00:03:05,110 --> 00:03:06,820 So we'll see if 30 00:03:10,510 --> 00:03:17,290 the x variable bloss Details variable 31 00:03:20,290 --> 00:03:23,860 is greater. 32 00:03:29,160 --> 00:03:37,290 So if the x variable Plus the Dick's variable is greater than the come fast 33 00:03:40,050 --> 00:03:40,720 with. 34 00:03:45,020 --> 00:03:48,260 Minus the borate Yes. 35 00:03:52,990 --> 00:04:06,670 So it explores the experienceable is greater than the covers weight minus the ball radius all this symbol 36 00:04:06,980 --> 00:04:26,630 of pipe Emens or all x bloss the x variable is less than the ball radius. 37 00:04:28,150 --> 00:04:28,630 Okay. 38 00:04:28,850 --> 00:04:31,250 So this is the statement here. 39 00:04:31,760 --> 00:04:41,630 So we're saying if this x plus the x is greater than the come of us with mine or the boy radios or if 40 00:04:41,750 --> 00:04:45,860 exploded the AIDS variable is less than the borate does. 41 00:04:45,860 --> 00:04:48,290 This is what should happen. 42 00:04:48,410 --> 00:04:57,830 We put calibrate since it should what should happen is that is either this condition is true. 43 00:04:57,830 --> 00:05:02,640 The first condition is true or it's a second condition is true. 44 00:05:02,720 --> 00:05:04,940 This is what we want to happen. 45 00:05:04,940 --> 00:05:13,950 We want the value of x to be equal to. 46 00:05:17,960 --> 00:05:23,900 Two equals two minus the decks. 47 00:05:23,930 --> 00:05:32,660 So this is what will happen if the first condition or the second condition is true in if it meant the 48 00:05:32,660 --> 00:05:38,380 value of Diddy's x variable would be it to minus the x variable. 49 00:05:38,520 --> 00:05:44,180 Thus we relate to the left and the right was of the compass. 50 00:05:44,450 --> 00:05:58,370 So for the top the bottom will be equal use the same code and being lasic one going to do just copy 51 00:05:58,450 --> 00:06:01,760 this if statement has changed the value. 52 00:06:06,840 --> 00:06:08,520 Copy here. 53 00:06:11,000 --> 00:06:15,510 Okay and I'll just change the values so it would be Y. 54 00:06:16,340 --> 00:06:21,430 If y plots the y 55 00:06:25,160 --> 00:06:30,560 y plausible y canvas dot right 56 00:06:34,040 --> 00:06:36,250 okay. 57 00:06:37,400 --> 00:06:52,560 Minus the ball radius or wine laws the Y is less than the boy radius. 58 00:06:52,810 --> 00:07:06,310 If that condition is true indeed y will be lost to a minus D Y. 59 00:07:06,890 --> 00:07:08,980 All right so this is State me too. 60 00:07:08,990 --> 00:07:19,230 Is it menhir I use to implement a simple coalition detection that will make the board change direction. 61 00:07:19,240 --> 00:07:21,700 If any completion is detected. 62 00:07:22,130 --> 00:07:23,250 So the first. 63 00:07:23,280 --> 00:07:28,300 What if statement here refers to the left and the right was of the compass. 64 00:07:28,310 --> 00:07:36,370 If the X blows the D X variables is greater than the compass with minors bore radius. 65 00:07:36,670 --> 00:07:43,760 No Remember I've declared the value of football radio so we're saying that the x variable Plus the variable 66 00:07:43,790 --> 00:07:49,230 is greater than become vets with minus the ball radios. 67 00:07:49,400 --> 00:08:00,050 Or if the x variable plots the defence variable is less than the ball radius then this condition between 68 00:08:00,050 --> 00:08:02,040 this curly braces will happen. 69 00:08:02,060 --> 00:08:10,310 That means the value of the X will be equal to or minus dicks in the second if statement. 70 00:08:10,310 --> 00:08:14,950 This will refer to the top and the bottom was on the Cambers. 71 00:08:15,140 --> 00:08:24,380 If the Y variable plods the D Y variable is greater than the converse height minus the ball radials 72 00:08:24,650 --> 00:08:31,610 or if y plus D Y variable is less than the ball radius. 73 00:08:31,850 --> 00:08:35,640 Then the condition between the curly braces will happen. 74 00:08:35,650 --> 00:08:42,860 That means the value of the D Y variable will be equal force to minus the Y. 75 00:08:43,100 --> 00:08:51,860 So this is just a simple coalition detection implementation using the if statements. 76 00:08:51,870 --> 00:08:59,720 See when the distance between the centre of the ball and the edge of the wall is exactly the same as 77 00:08:59,720 --> 00:09:01,340 the radius of the ball. 78 00:09:01,340 --> 00:09:10,670 It will change the direction of movement so subtracting the radials from one edge with an add in it 79 00:09:10,670 --> 00:09:17,480 on to dolar give the impression that some coalition has been detected and then the ball bounces off 80 00:09:17,510 --> 00:09:18,770 the wall. 81 00:09:19,550 --> 00:09:22,280 So save the code. 82 00:09:23,390 --> 00:09:29,360 Okay then check are hastier mount and see what the code looks like. 83 00:09:29,370 --> 00:09:33,360 Go run lunch in Chrome. 84 00:09:33,560 --> 00:09:37,490 We should have a proper coalition detection you see that. 85 00:09:37,840 --> 00:09:40,810 So the ball is now within the compass. 86 00:09:41,080 --> 00:09:48,170 Cause there's a collision detection in place it says bouncing off the walls of the compass so that's 87 00:09:48,170 --> 00:09:50,980 it for this project. 88 00:09:51,230 --> 00:09:54,030 Thank you so much for your time in watching. 89 00:09:54,350 --> 00:10:00,580 If you have any questions whatsoever please do not hesitate to contact me. 90 00:10:00,690 --> 00:10:09,590 TRAMP practice and change some of the values of what we have learned and just play around to familiarize 91 00:10:09,590 --> 00:10:13,350 yourself with the way things work. 92 00:10:13,400 --> 00:10:19,280 Don't be scared to break anything you can always make copies of your original code and just try and 93 00:10:19,280 --> 00:10:19,990 break it. 94 00:10:20,000 --> 00:10:23,980 Try new things and improve your skills. 95 00:10:23,990 --> 00:10:25,030 Thank you so much. 96 00:10:25,040 --> 00:10:25,920 And by for.